A path (or filepath, file path, pathname, or similar) is a text string that uniquely specifies an item in a hierarchical file system. Generally, a path is composed of directory names, special directory specifiers and optionally a filename, separated by delimiter. The delimiter varies by operating system and in theory can be anything, but popular, modern systems use slash , backslash , or colon .
A path can be either relative or absolute. A relative path includes information that is relative to a particular directory whereas an absolute path indicates a location relative to the system root directory, and therefore, does not depends on context like a relative path does. Often, a relative path is relative to the working directory. For example, in command , is a relative path to the file with that name in the working directory.
Paths are used extensively in computer science to represent the directory/file relationships common in modern operating systems and are essential in the construction of uniform resource locators (URLs).
Around 1970, Unix introduced the slash character ("/") as its directory separator.
Originally, MS-DOS did not support directories, but when adding the feature, using the Unix standard of slash was not a good option since many existing commands used slash as the switch prefix. For example, dir /w. In contrast, Unix uses dash as the switch prefix. In this context, MS-DOS version 2.0 used backslash for the path delimiter since it is similar to slash but did not conflict with existing commands. This convention continued into Windows in its shell Command Prompt. Eventually, PowerShell, was introduced to Windows that is slash-agnostic, allowing the use of either slash in a path.
Japanese and Korean versions of Windows often display the '¥' character or the 'Won sign' character instead of the directory separator. In such cases the code for a backslash is being drawn as these characters. Very early versions of MS-DOS replaced the backslash with these glyphs on the display to make it possible to display them by programs that only understood 7-bit ASCII (other characters such as the square brackets were replaced as well, see ISO 646, Windows Codepage 932 (Japanese Shift JIS), and Codepage 949 (Korean)). Although even the first version of Windows supported the 8-bit ISO-8859-1 character set which has the Yen sign at U+00A5, and modern versions of Windows supports Unicode which has the Won sign at U+20A9, much software will continue to display backslashes found in ASCII files this way to preserve backward compatibility.
macOS, as a derivative of UNIX, uses UNIX paths internally. However, to preserve compatibility for software and familiarity for users, many portions of the GUI switch "/" typed by the user to ":" internally, and switch them back when displaying filenames (a ":" entered by the user is also changed into "/" but the inverse translation does not happen).
/
/
This direct access to the operating system paths can hinder the portability of programs. To support portable programs Java uses File.separator to distinguish between / and \ separated paths. Seed7 has a different approach for the path representation. In Seed7 all paths use the Unix path convention, independent of the operating system. Under windows a mapping takes place (e.g.: The path /c/users is mapped to c:\users).
\\ComputerName\SharedFolder\Resource
Some Windows interfaces allow or require UNC syntax for WebDAV share access, rather than a URL. The UNC syntax is extended with optional components to denote use of SSL and TCP/IP port number, a WebDAV URL of . becomes
\\HostName[@SSL][@Port]\SharedFolder\Resource
When viewed remotely, the "SharedFolder" may have a name different from what a program on the server sees when opening "\SharedFolder". Instead, the SharedFolder name consists of an arbitrary name assigned to the folder when defining its "sharing".
Some Windows interfaces also accept the "Long UNC":
\\?\UNC\ComputerName\SharedFolder\Resource
Windows uses the following types of paths:
In versions of Windows prior to Windows XP, only the APIs that accept "long" device paths could accept more than 260 characters.
The Windows shell in Windows XP and Windows Vista, explorer.exe, allows path names up to 248 characters long.
Since UNCs start with two backslashes, and the backslash is also used for string escaping and in regular expressions, this can result in extreme cases of leaning toothpick syndrome: an escaped string for a regular expression matching a UNC begins with 8 backslashes – ''[drive letter:]''\ – because the string and regular expression both require escaping. This can be simplified by using , as in C#'s \\''[server name]''\''[volume]''\ or Python's \, or regular expression literals, as in Perl's ..
hostname:/directorypath/resource
or URI schemes with the service name (here 'smb'):
smb://hostname/directorypath/resource
Given the working directory is and it contains subdirectory , relative paths to the subdirectory include and , and the absolute path is . A command to change the working directory to the subdirectory:
Unlike Unix that always has a single root directory, a Windows file system has a root for each storage drive. An absolute path includes a drive letter or uses the UNC format.
A UNC path (starting with ) does not support slashes.
.. is an absolute path that specifies a file named in the directory which is in the root of drive :
C:\USER\DOCS\LETTER.TXT is a relative path that specifies file located in the parent of the working directory on drive :
A:PICTURE.JPG is a relative path that specifies file in directory which is in directory which is in the working directory of the current drive:
\\SERVER01\USER\DOCS\LETTER.TXT is a relative path that specifies ''[drive letter:]''\ in the working directory:
\\''[server name]''\''[volume]''\ specifies the first serial port, COM1:
The following uses a path with slashes for directory delimiter:
386Enh
woafont=dosapp.fon
EGA80WOA.FON=EGA80WOA.FON
EGA40WOA.FON=EGA40WOA.FON
CGA80WOA.FON=CGA80WOA.FON
CGA40WOA.FON=CGA40WOA.FON
...
A path with forward slashes may need to be surrounded by double quotes to disambiguate from command-line switches. For example, is invalid, but is valid. And is more lenient by allowing .
|
|